package dbutils02;

import org.apache.commons.dbutils.QueryRunner;
import org.junit.Before;
import org.junit.Test;

import java.sql.SQLException;

public class DBUtilsDemo02 {
    private QueryRunner qr;
    @Before
    public void  initQueryRunnner(){
        qr = new QueryRunner(JDBCUtils.getDataSource());
    }

    @Test
    public void  testInsert() throws Exception {

        int i = qr.update("INSERT  INTO  test.product values (?,?,?)",
                14, "airpods2", 1200);
        System.out.println(i);

    }
    @Test
    public void testUpdate()throws Exception{
        //修改三星 4K 液晶电视的价格,要求在原价的基础上增长 3000 块
        int i = qr.update("UPDATE product SET price = price+3000 WHERE pid=?"
                , 14);
        System.out.println(i);
    }
    @Test
    public void testDelete()  throws  Exception{
        int i = qr.update("delete  from product where pname=?",
                "airpods2");
        System.out.println(i);
    }

}
